class DuplicateKeyError(Exception):
    pass

class ColumnCalculator(object):
    def __init__(self, four_vectors, v4cols, fl=[]):
        self._fmap = {}
        self._names = []
        self.v4cols = set(v4cols)
        for f in fl:
            self.add(f)

        self.four_vectors = four_vectors

    def add(self, name, f):
        if name in self._fmap:
            msg = "Entry `{}' already present"
            raise DuplicateKeyError(msg)
        
        self._names.append(name)
        self._names.sort()

        self._fmap[name] = f

    def __contains__(self, key):
        return key in self._fmap

    def __getitem__(self, key):
        if type(key) == type("howdy!"):
            return self._fmap[key]
        else:
            return self._fmap[self._names[key]]

    def __iter__(self):
        for n in self._names:
            yield self._fmap[n]
    
        
